﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Server
{
    class Format
    {
        public static string NumberFormat(string src)
        {
            try
            {
                int length = src.Length;
                if (length > 3)
                {
                    StringBuilder des = new StringBuilder();
                    int segment = length / 3;
                    int mod = length % 3;
                    if(mod>0)
                    {
                       des.Append(src.Substring(0,mod));
                       des.Append(",");
                    }
                    for (int i = 0; i < segment; i++)
                    {
                        if (i != 0)
                        {
                            des.Append(",");
                        }
                        des.Append(src.Substring((i * 3) + mod, 3));
                    }
                    return des.ToString();
                }
                return src;
            }
            catch
            {
                return "0";
            }
        }
    }
}
